// Interface data format used to return a unified format
import { Recordable } from 'vite-plugin-mock'

export function resultSuccess<T = Recordable>(data:T, {message = 'ok'} = {}){
  return {
    code: 0,
    data,
    message,
    type:'sucess'
  }
}

export function resultError(message = 'Request faild', {code = '-1',data = null}= {}){
  return {
    code,
    data,
    message,
    type:'error'
  }
}

/**
 * 请求接口的参数类型定义
 */
 export interface requestParams {
  method: string
  body: any
  headers ?: { authorization?: string }
  query:any
}


/**
 * @description 本函数用于从request数据中获取token，请根据项目的实际情况修改
 *
 */
export function getRequestToken({ headers }: requestParams){
  return headers?.authorization
}
